/*
 * uart.c
 * UART�ӿ�
 * ����: 2016.11.11
 * ����: ̷����
 */

#include "main.h"
#include "usart.h"
#include "scs_uart.h"

//UART �����ݻ�����
__IO uint8_t uart1Buf[128];
__IO int head1 = 0;
__IO int tail1  = 0;

void SCS_Uart_Flush(void)
{
	head1 = tail1 = 0;
}

short SCS_Uart_Read(void)
{
	if(head1!=tail1){
		uint8_t Data = uart1Buf[head1];
		head1 =  (head1+1)%128;
		return Data;
	}else{
		return -1;
	}
}

void SCS_Uart_RxCallback(void)
{
		uart1Buf[tail1] = USART2->DR;
		tail1 = (tail1+1)%128;
}

void SCS_Uart_DmaSend(uint8_t *buf , uint8_t len)
{
	HAL_UART_Transmit(&huart2, buf, len, 0xff);
}
